#include "inclusionsXXX.inc"
 #include "functions.inc"
 

background{color White}
 

/*
    global_settings
{
 max_trace_level 255
radiosity
{
pretrace_start 0.16
pretrace_end 0.01
count 600
nearest_count 4
error_bound 0.1
recursion_limit 1
low_error_factor 1
gray_threshold 0.0
minimum_reuse 0.015
brightness 0.2
adc_bailout 0.01/2
}
photons
{
count 200000
jitter .1
}
}
*/









camera{
 location<0,4.3,-3>*2
 look_at<0,0,0>
 }
 

/*
 light_source
{
0*x
color White
area_light
<4, 0, 0> <0, 0, 4>
5, 5
adaptive 0.2
jitter
circular
orient
translate <140,150,-200>*0.05

photons {
refraction on
reflection on
}
media_attenuation on
}

light_source
{
0*x
color White
area_light
<4, 0, 0> <0, 0, 4>
5, 5
adaptive 0.2
jitter
circular
orient
translate <-140,150,-200>*0.05

photons {
refraction on
reflection on
}
media_attenuation on
}
*/
light_source{
<-2,20,2>*0
color White
shadowless
}

light_source{
<-140,150,-200>
color White
}


#declare rayon=1.2; 
#declare r2=0.2; 
#declare r1=1; 



#declare fi=(1+sqrt(5))/2; 
#declare sommet=array[3];
#declare arete=2; 
#declare radi=arete/2*sqrt(2+fi);

#declare auxi1=sqrt(1-1/(4*cos(3*pi/10)*cos(3*pi/10)))*2/sqrt(3); 
#declare miangle=90-acos(auxi1)*180/pi; 
#declare grandR=arete/(2*cos(3*pi/10)); 
#declare petitr=sqrt(grandR*grandR-arete*arete/4); 
#declare petith=sqrt(arete*arete-grandR*grandR); 
#declare grandH=sqrt(3)*arete/2; 
#declare miangle=90-acos(petith/grandH)*180/pi; 
#declare partieVerticale=sqrt(grandH*grandH-(grandR-petitr)*(grandR-petitr)); 
#declare decale=(partieVerticale/2+petith); 
#declare angleV=acos((grandR-petitr)/grandH)*180/pi; 
#declare fi=(1+sqrt(5))/2; 
#declare grandL=arete*(1+fi)/(2-fi); 

// definition des transformations
#declare Tran=array[20]; 
#declare index=0; 
#while(index<5)
#declare Tran[index]=
transform{
translate -arete*sqrt(3)/3*x
rotate miangle*z
rotate index*72*y
translate decale*y
}
#declare index=index+1; 
#end 

#declare index=0; 
#while(index<5)
#declare Tran[index+5]=
transform{
translate -arete*sqrt(3)/3*x
rotate -miangle*z
rotate (36+index*72)*y
translate -decale*y
}
#declare index=index+1; 
#end 

#declare index=0; 
#while(index<5)
#declare Tran[index+10]=
transform{
translate -arete*sqrt(3)/3*x
rotate (180-angleV)*z 
translate partieVerticale/2*y 
translate -grandR*x
rotate (36+72*index)*y
}
#declare index=index+1; 
#end 

#declare index=0; 
#while(index<5)
#declare Tran[index+15]=
transform{
translate -arete*sqrt(3)/3*x
rotate -angleV*z 
translate -partieVerticale/2*y 
translate grandR*x
rotate (36+72*index)*y
}
#declare index=index+1; 
#end 






#declare tprism=
prism{
linear_sweep
linear_spline
-1,
1,
4
<cos(2*0*pi/3),sin(2*0*pi/3)>*arete*sqrt(3)/3, 
<cos(2*1*pi/3),sin(2*1*pi/3)>*arete*sqrt(3)/3, 
<cos(2*2*pi/3),sin(2*2*pi/3)>*arete*sqrt(3)/3, 
<cos(2*0*pi/3),sin(2*0*pi/3)>*arete*sqrt(3)/3 
//texture{pigment{color White}}
finish {reflection 0.3}
}

#declare S=array[3]; 

#declare S[0]=<cos(2*0*pi/3),0,sin(2*0*pi/3)>*arete*sqrt(3)/3;  
#declare S[1]=<cos(2*1*pi/3),0,sin(2*1*pi/3)>*arete*sqrt(3)/3;  
#declare S[2]=<cos(2*2*pi/3),0,sin(2*2*pi/3)>*arete*sqrt(3)/3; 


#declare G=array[3]; 
#declare G[1]=<-1,0,0>*grandL*sqrt(3)/3;
#declare G[2]=<cos(5*pi/3),0,sin(5*pi/3)>*grandL*sqrt(3)/3; 
#declare G[0]=<cos(pi/3),0,sin(pi/3)>*grandL*sqrt(3)/3;


#declare A=array[3]; 
#declare A[0]=<grandL*sqrt(3)/6,0,(fi-1)/(1+fi)*grandL/2>; 
#declare A[1]=vrotate(A[0],<0,-120,0>);
 #declare A[2]=vrotate(A[0],<0,120,0>);


#declare B=array[3]; 
#declare B[0]=<grandL*sqrt(3)/6,0,-(fi-1)/(1+fi)*grandL/2>; 
#declare B[1]=vrotate(B[0],<0,-120,0>);
 #declare B[2]=vrotate(B[0],<0,120,0>);
 
 #declare C=array[3]; 
#declare C[2]=(B[1]+G[2])/2; 
#declare C[0]=(B[2]+G[0])/2; 
#declare C[1]=(B[0]+G[1])/2; 

#declare D=array[3]; 
#declare D[1]=(A[0]+G[1])/2; 
#declare D[0]=(A[2]+G[0])/2; 
#declare D[2]=(A[1]+G[2])/2; 

#declare E=array[3]; 
#declare E[0]=(D[2]+B[0])/2; 
#declare E[1]=(A[2]+G[0])/2; 
#declare E[2]=(A[1]+G[2])/2; 


#macro droiteEquation(V1,V2)
<(V2.z-V1.z)/(V2.x-V1.x),V1.z-V1.x*(V2.z-V1.z)/(V2.x-V1.x)>
#end

#macro intersect(ED1,ED2)
#local denom=ED2.x-ED1.x; 
#local numx=ED1.y-ED2.y; 
#local numy=ED1.y*ED2.x-ED2.y*ED1.x; 
<numx/denom,0,numy/denom>
#end

#declare E=array[3]
#declare ed1=droiteEquation(G[1],A[0]);
#declare ed2= droiteEquation(A[1],A[2]);
#declare E[1]=intersect(ed1,ed2); 
#declare E[2]=vrotate(E[1],<0,-120,0>);
#declare E[0]=vrotate(E[1],<0,120,0>);

#declare F=array[3]
#declare ed1=droiteEquation(G[0],B[2]);
#declare ed2= droiteEquation(B[1],B[0]);
#declare F[0]=intersect(ed1,ed2); 
#declare F[1]=vrotate(F[0],<0,-120,0>);
#declare F[2]=vrotate(F[0],<0,120,0>);

#declare H=array[3]
#declare ed1=droiteEquation(B[0],B[1]);
#declare ed2= droiteEquation(B[2],A[0]);
#declare H[0]=intersect(ed1,ed2); 
#declare H[1]=vrotate(H[0],<0,-120,0>);
#declare H[2]=vrotate(H[0],<0,120,0>);

#declare I=array[3]
#declare ed1=droiteEquation(A[0],A[2]);
#declare ed2= droiteEquation(B[1],B[0]);
#declare I[0]=intersect(ed1,ed2); 
#declare I[1]=vrotate(I[0],<0,-120,0>);
#declare I[2]=vrotate(I[0],<0,120,0>);

#declare J=array[3]
#declare ed1=droiteEquation(A[0],A[1]);
#declare ed2= droiteEquation(B[1],B[0]);
#declare J[0]=intersect(ed1,ed2); 
#declare J[1]=vrotate(J[0],<0,-120,0>);
#declare J[2]=vrotate(J[0],<0,120,0>);

#declare K=array[3]
#declare ed1=droiteEquation(B[1],G[2]);
#declare ed2= droiteEquation(A[0],G[1]);
#declare K[0]=intersect(ed1,ed2); 
#declare K[1]=vrotate(K[0],<0,-120,0>);
#declare K[2]=vrotate(K[0],<0,120,0>);


#declare L=array[3]
#declare ed1=droiteEquation(B[0],A[1]);
#declare ed2= droiteEquation(A[0],A[2]);
#declare L[2]=intersect(ed1,ed2); 
#declare L[0]=vrotate(L[2],<0,-120,0>);
#declare L[1]=vrotate(L[2],<0,120,0>);


#macro plat(V)
<V.x,V.z>
#end

// Compound of five tetrahedra
#declare comp5tetra=
union{
#local ix=0; 
#while(ix<3)
prism{
linear_sweep
linear_spline
-10,
10,
4,
plat(S[ix]),
plat(D[ix]),
plat(K[ix]),
plat(S[ix])
}
prism{
linear_sweep
linear_spline
-10,
10,
4,
plat(S[ix]),
plat(C[mod(ix+2,3)]),
plat(K[mod(ix+2,3)]),
plat(S[ix])
}
#local ix=ix+1; 
#end
}



#declare seventhStellation=union{
prism{
linear_sweep
linear_spline
-0.001,
0.001,
4,
plat(A[1]),
plat(S[1]),
plat(D[1]),
plat(A[1])
}
prism{
linear_sweep
linear_spline
-0.001,
0.001,
4,
plat(A[2]),
plat(S[2]),
plat(D[2]),
plat(A[2])
}
prism{
linear_sweep
linear_spline
-0.001,
0.001,
4,
plat(A[0]),
plat(S[0]),
plat(D[0]),
plat(A[0])
}
prism{
linear_sweep
linear_spline
-0.001,
0.001,
4,
plat(B[1]),
plat(S[1]),
plat(C[0]),
plat(B[1])
}
prism{
linear_sweep
linear_spline
-0.001,
0.001,
4,
plat(B[2]),
plat(S[2]),
plat(C[1]),
plat(B[2])
}
prism{
linear_sweep
linear_spline
-0.001,
0.001,
4,
plat(B[0]),
plat(S[0]),
plat(C[2]),
plat(B[0])
}
}


#declare sixthStellation=union{
prism{
linear_sweep
linear_spline
-1,
1,
5
plat(G[0]),
plat(F[0]),
plat(J[0]),
plat(E[0]),
plat(G[0])
}
prism{
linear_sweep
linear_spline
-1,
1,
5
plat(G[1]),
plat(F[1]),
plat(J[1]),
plat(E[1]),
plat(G[1])
}
prism{
linear_sweep
linear_spline
-1,
1,
5
plat(G[2]),
plat(F[2]),
plat(J[2]),
plat(E[2]),
plat(G[2])
}

prism{
linear_sweep
linear_spline
-1,
1,
6
plat(A[1]),
plat(B[1]),
plat(L[0]),
plat(I[1]),
plat(H[1]),
plat(A[1])
}
prism{
linear_sweep
linear_spline
-1,
1,
6
plat(A[2]),
plat(B[2]),
plat(L[1]),
plat(I[2]),
plat(H[2]),
plat(A[2])
}
prism{
linear_sweep
linear_spline
-1,
1,
6
plat(A[0]),
plat(B[0]),
plat(L[2]),
plat(I[0]),
plat(H[0]),
plat(A[0])
}

}
// fourteenth
#declare fourteenth=union{
#local ix=0; 
#while(ix<3)
prism{
linear_sweep
linear_spline
-1,
1,
4,
plat(A[ix]),
plat(B[ix]),
plat(D[ix]),
plat(A[ix])
}
prism{
linear_sweep
linear_spline
-1,
1,
4,
plat(B[ix]),
plat(D[mod(ix+2,3)]),
plat(K[mod(ix+2,3)]),
plat(B[ix])
}
#local ix=ix+1; 
#end
}// 14th
 
#declare Ff=function {f_mesh1
  //(x, y, z, 0.15, 0.15, 5, 0.02, 0.2) - 0.03}
  (x, y, z, 0.1, 0.1, 2, 0.01, 2)-0.03}
#declare grille=isosurface {
  //function { F(f_ph(x,y,z), f_r(x,y,z)-1, f_th(x,y,z)) }
 	function{Ff(x,y,z)}
 
 //accuracy 0.001
        max_gradient 2.2
  contained_by {sphere { 0,rayon*10 } }
  //texture{pigment{color White}}
  finish{Metallic_Finish}
  }
 
 #macro montrig(col)
 intersection{ 
 object{fourteenth texture{pigment{color col}}}
 object{ grille texture{pigment{color col}}}
 
 }
 #end
 
 #macro labase(xx)
union{
#declare index=0; 
#while(index<20)
object{
xx


//texture{pigment{color White}}
transform Tran[index]
}
#declare index=index+1; 
#end
}
#end
 
 
 object{labase(montrig(White)) }
 /*
 object{
 labase(montrig(Red))
 scale 0.707
 
 
 }
 
 object{
 labase(montrig(Yellow))
 scale 0.707*0.707
 }
 */
 
 //object{montrig(White)}
 plane{y,-5 texture{pigment{color Blue}} finish{specular 0.3}}
 